# 节省内存

import torch

Y = torch.tensor([[2.0, 1, 4, 3], [1, 2, 3, 4], [4, 3, 2, 1]])
X = torch.arange(12, dtype=torch.float).reshape(3, 4)

before =id(Y)
Y = Y + X

print(id(Y) == before)

Z = torch.zeros_like(Y)
print('id Z:', id(Z))
Z[:] = X + Y
print('id Z:', id(Z))